var _nobleGase = Map<int, String>();

bool isNoble(int atomicNumber) {
  return _nobleGase[atomicNumber] != null;
}

isnoble(int atomicNumber) {
  return _nobleGase[atomicNumber] != null;
}

bool _isNoble(int atomicNumber) => _nobleGase[atomicNumber] != null;

bool topLevel = true;

void main(List<String> arguments) {
  _nobleGase[2] = 'helium';
  _nobleGase[10] = 'neon';
  _nobleGase[18] = 'argon';

  enableFlags(bold: true, hidden: false);
  enableflags(bold: true);

  assert(say('boy', 'Howdy') == 'boy says Howdy');
  assert(
    say('Bob', 'Howdy', 'smoke signal') == 'Bob says Howdy with a smoke signal',
  );
  assert(says('Bob', 'Howdy') == 'Bob says Howdy with a carrier pigeon');
  print('Hello, World!');
  print(arguments);
  var list = [1, 2, 3];
  list.forEach(printElement);
  assert(loudify('hello') == '!!! HELLO !!!');
  void Function(String, {String greeting}) g = greet;
  g('Dash', greeting: 'Howdy');

  const list_1 = ['apples', 'bananas', 'oranges'];
  var uppercaseList =
      list_1.map((item) {
        return item.toUpperCase();
      }).toList();
  for (var item in uppercaseList) {
    print('$item: ${item.length}');
  }
  var upperCaseList = list_1.map((item) => item.toUpperCase()).toList();
  upperCaseList.forEach((item) => print('$item: ${item.length}'));

  var insideMain = true;
  void myFunction() {
    var insideFunction = true;
    void nestedFunction() {
      var insideNestedFunction = true;
      assert(topLevel);
      assert(insideMain);
      assert(insideFunction);
      assert(insideNestedFunction);
    }
  }

  var add2 = makeAdder(2);
  var add4 = makeAdder(4);
  assert(add2(3) == 5);
  assert(add4(3) == 7);

  var charCodes = [68, 97, 114, 116];
  var buffer = StringBuffer();
  charCodes.forEach(print);
  charCodes.forEach(buffer.write);

  Function x;
  x = foo;
  assert(foo == x);
  x = A.bar;
  assert(A.bar == x);
  var v = A();
  var w = A();
  var y = w;
  x = w.baz;
  assert(y.baz == x);
  assert(v.baz != w.baz);

  Foo() {}
  assert(Foo() == null);
}

void enableFlags({bool? bold, bool? hidden}) {}
void enableflags({bool bold = false, bool hidden = false}) {}

String say(String from, String msg, [String? device]) {
  var result = '$from says $msg';
  if (device != null) {
    result = '$result with a $device';
  }
  return result;
}

String says(String from, String msg, [String device = 'carrier pigeon']) {
  var result = '$from says $msg with a $device';
  return result;
}

void printElement(int element) {
  print(element);
}

var loudify = (msg) => '!!! ${msg.toUpperCase()} !!!';

void greet(String name, {String greeting = 'Hello'}) =>
    print('$greeting $name!');

Function makeAdder(int addBy) {
  return (int i) => addBy + i;
}

void foo() {}

class A {
  static void bar() {}
  void baz() {}
}

(String, int) _foo() {
  return ('something', 42);
}

Iterable<int> naturalsTo(int n) sync* {
  int k = 0;
  while (k < n) yield k++;
}

Stream<int> asynchronousNaturalsTo(int n) async* {
  int k = 0;
  while (k < n) yield k++;
}

Iterable<int> naturalsDownFrom(int n) sync* {
  if (n > 0) {
    yield n;
    yield* naturalsDownFrom(n - 1);
  }
}
